package com.zzy.ymcc.web.controller;


import com.zzy.ymcc.dto.SmsCodeDto;
import com.zzy.ymcc.result.JSONResult;
import com.zzy.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult image(@PathVariable("imageCodeKey")String key){
        try {
            //调用业务代码获取图形验证码（base64编码的字符串）
            String base64Str = verifyCodeService.image(key);
            //将（base64编码的字符串）响应给前端
            return JSONResult.success().setData(base64Str);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"获取图形验证码失败","104564");
        }
    }

    @RequestMapping(value = "/sendSmsCode",method = RequestMethod.POST)
    public JSONResult smsCode(@RequestBody SmsCodeDto smsCodeDto){
        verifyCodeService.sendSms(smsCodeDto);
        return JSONResult.success();
    }

//    ///verifyCode/binderSmsCode
//    @PostMapping("/binderSmsCode")
//    public JSONResult binderSmsCode(@RequestBody SmsCodeDto smsCodeDto){
//        try {
//            verifyCodeService.binderSmsCode(smsCodeDto);
//            return new JSONResult();
//            // 添加业务异常
//        } catch (BusinessException e) {
//            e.printStackTrace();
//            return new JSONResult(false,e.getMessage());
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new JSONResult(false,"获取手机验证码失败");
//        }
//    }


}